﻿namespace UDKDevKitVSXDebugEngine.Classes
{
    using System;
    using System.Diagnostics;
    using UDKDevKitVSXCore.Classes;

    public class UDKCommands
    {
        public const string StopDebugging = "stopdebugging";
        public const string Go = "go";
        public const string StepInto = "stepinto";
        public const string StepOver = "stepover";
        public const string StepOutOf = "stepoutof";
        public const string AddBreakpoint = "addbreakpoint {0} {1}";
        public const string RemoveBreakpoint = "removebreakpoint {0} {1}";
        public const string BreakOnNone = "breakonnone {0}";
        public const string SetDataWatch = "setdatawatch {0}";
        public const string Break = "break";
    }

    public class VSCommandSender : IpcCommandSender
    {
        public VSCommandSender()
            : base("UDKSide")
        {
        }

        public void Continue()
        {
            Debug.WriteLine(string.Concat("VSCommandSender: send ", UDKCommands.Go));

            Send(UDKCommands.Go);
        }

        public void StopDebugging()
        {
            Send(UDKCommands.StopDebugging);
        }

        internal void StepBackwards()
        {
            Debug.Fail("NotImplementedException");
            throw new NotImplementedException();
        }

        internal void StepInto()
        {
            Send(UDKCommands.StepInto);
        }

        internal void StepOut()
        {
            Send(UDKCommands.StepOutOf);
        }

        internal void StepOver()
        {
            Send(UDKCommands.StepOver);
        }

        internal void SetBreakpoint(string className, uint line)
        {
            Send(string.Format(UDKCommands.AddBreakpoint, className, line));
        }
        
        internal void RemoveBreakpoint(string className, uint line)
        {
            Send(string.Format(UDKCommands.RemoveBreakpoint, className, line));
        }

        internal void SetBreakOnNone()
        {
            Send(string.Format(UDKCommands.BreakOnNone, "1"));
        }

        internal void SetDataWatch(string funcName)
        {
            Send(string.Format(UDKCommands.SetDataWatch, funcName));
        }

        internal void RemoveBreakOnNone()
        {
            Send(string.Format(UDKCommands.BreakOnNone, "0"));
        }

        internal void RemoveDataWatch(string funcName)
        {
            // todo: there is no such function
        }

        internal void Break()
        {
            Send(UDKCommands.Break);
        }
    }
}